package com.jsbj.user.controller;


import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.page.PageReq;
import com.jsbj.tools.RequestHeaderUtils;
import com.jsbj.user.entities.SysRole;
import com.jsbj.user.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/sys-role")
//@ApiIgnore
@Api(value = "系统角色", tags = "系统角色")
public class SysRoleController extends BaseController {

    @Autowired
    private ISysRoleService sysRoleService;

    @Autowired
    private HttpServletRequest request;

    @ApiOperation(value = "添加角色")
    @PostMapping("/add")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true)}
    )
    public ResultBean<Integer> add(@RequestBody SysRole sysRole) throws Exception {
        return new ResultBean<>(sysRoleService.add(sysRole));
    }

    @ApiOperation(value = "详情")
    @ResponseBody
    @PostMapping("/detail")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean<SysRole> detail(@RequestParam String id) {
        return new ResultBean<>(sysRoleService.detail(id));
    }

    @ApiOperation(value = "停用")
    @ResponseBody
    @PostMapping("/delete")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean delete(@RequestParam String id) throws Exception {
        return new ResultBean<Integer>(sysRoleService.delete(id));
    }

    @ApiOperation(value = "查询列表")
    @ResponseBody
    @PostMapping("/list")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "页码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页条数", required = true)}
    )
    public ResultBean<PageReq> getList(@RequestBody String inParam) {
        //保存日志
        String userId = RequestHeaderUtils.getUserId(request);
        return new ResultBean<PageReq>(getPage(sysRoleService.getList(inParam)));
    }

    @ApiOperation(value = "启用")
    @ResponseBody
    @PostMapping("/startUsing")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "数据id", required = true)}
    )
    public ResultBean startUsing(@RequestParam String id){
        return new ResultBean<Integer>(sysRoleService.startUsing(id));
    }

    @ApiOperation("根据项目、标段查询角色列表")
    @GetMapping("/getRoleListByTenantCodeAndOrgCode")
    public ResultBean<List<SysRole>> getRoleListByTenantCodeAndOrgCode(@RequestParam String tenantCode, @RequestParam String orgCode) {
        return new ResultBean<List<SysRole>>(sysRoleService.getRoleListByTenantCodeAndOrgCode(tenantCode,orgCode));
    }

    @ApiOperation("根据项目查询角色列表")
    @GetMapping("/getRoleListByTenantCode")
    public ResultBean<List<SysRole>> getRoleListByTenantCode(@RequestParam String tenantCode) {
        return new ResultBean<List<SysRole>>(sysRoleService.getRoleListByTenantCode(tenantCode));
    }



}

